#ifndef __mytime__
#define __mytime__

// 从互联网同步时间到芯片
bool SetRTCTime() {
  // Variables to save date and time
  String formattedDate;
  String dayStamp;

  bool ret = timeClient.update();
  if (ret) {

#ifdef _RTC_
    // The formattedDate comes with the following format: 2018-05-28T16:00:13Z
    // We need to extract date and time
    formattedDate = timeClient.getFormattedDate();
    // Serial.println(formattedDate);
    // Extract date
    int splitT = formattedDate.indexOf("T");
    dayStamp = formattedDate.substring(0, splitT);
    rtc.set(timeClient.getSeconds(),
            timeClient.getMinutes(),
            timeClient.getHours(),
            timeClient.getDay(),
            dayStamp.substring(8, 10).toInt(),
            dayStamp.substring(5, 7).toInt(),
            dayStamp.substring(2, 4).toInt());
    // note: RTCLib::set(byte second, byte minute, byte hour, byte dayOfWeek,
    // note:             byte dayOfMonth, byte month, byte year)

#else
    hour = timeClient.getHours(),
    minu = timeClient.getMinutes(),
    seco = timeClient.getSeconds(),
#endif

    ntptime = timeClient.getFormattedTime() + " - DOW: " + timeClient.getDay();
  }

  return ret;
}

#endif